import { getDeptTreeApi } from "@/api/managementCenter/departmentPersonnel";
import { reactive, ref } from "vue";

export default function InitHook() {
  const formState = reactive<Partial<{ deptId: Array<string> }>>({
    deptId: []
  });
  const formDataRef = ref<any>(null);
  const departmentOpts = ref<Array<Base.GeneraDataType>>([]);
  const filter = (inputValue: string, path: Array<Base.GeneraDataType>) => {
    return path.some(option => option.label.toLowerCase().indexOf(inputValue.toLowerCase()) > -1);
  };
  const getDeptTree = () => {
    return getDeptTreeApi().then((res: any) => {
      const { code, data } = res;
      if (code === 200) {
        departmentOpts.value = data || [];
      }
    });
  };
  return {
    formState,
    formDataRef,
    departmentOpts,
    filter,
    getDeptTree
  };
}
